﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Text;
using System.Collections;
using cmsservice.Common;

/// <summary>
///EPioneerDataBLL 的摘要说明
/// </summary>
public class EPioneerDataBLL
{
    public EPioneerDataBLL()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }
    EPioneerDataDAL dal = new EPioneerDataDAL();

    #region 今日要闻精选

    /// <summary>
    /// 获取今日要闻精选 ，包括财经新闻(内地财经)、异动板块、新闻和异动888888中的最新一条数据
    /// </summary>
    /// <returns></returns>
    public IEnumerable GetChoicenessNews()
    {
        IEnumerable elist = null;
        List<NewsTextModel> list = new List<NewsTextModel>();
        object o = Cache.Get("GetChoicenessNews");
        if (o == null)
        {
            list = GetNeidiNews(list, "1");
            list = GetXinwenNews(list, "1");
            list = GetYidongNews(list, "1");
            list = GetStockAbnormalNews(list);
            if (list != null)
            {
                elist = list.OrderByDescending(p => p.PublDate).Take(200);
                Cache.Add("GetChoicenessNews", elist, DateTime.Now.AddMinutes(5));
            }
        }
        else
            elist = o as IEnumerable;
        return elist;
    }

    /// <summary>
    /// 获取后台维护的精选信息，包括异动板块56、股市直播54、个股异动0和要闻0101
    /// </summary>
    /// <returns></returns>
    public IEnumerable GetChoicenessNewsInfo()
    {
        IEnumerable elist = null;
        List<NewsTextModel> list = new List<NewsTextModel>();
        object o = Cache.Get("GetChoicenessNewsInfo");
        if (o == null)
        {
            list = GetGeGuYidongNews(list, "1");
            list = GetYidongNews(list, "1", "54");
            list = GetYidongNews(list, "1", "56");
            list = GetNewListWhere(list, "1");
            if (list != null)
            {
                elist = list.OrderByDescending(p => p.PublDate).Take(200);
                Cache.Add("GetChoicenessNewsInfo", elist, DateTime.Now.AddMinutes(5));
            }
        }
        else
            elist = o as IEnumerable;
        return elist;
    }

    #endregion

    #region 今日要闻

    /// <summary>
    /// 获取后台维护的信息，包括异动板块56、股市直播54、个股异动0和要闻0101
    /// </summary>
    /// <returns></returns>
    public IEnumerable GetAllNewsInfo()
    {
        IEnumerable elist = null;
        List<NewsTextModel> list = new List<NewsTextModel>();
        object o = Cache.Get("GetAllNewsInfo");
        if (o == null)
        {
            list = GetGeGuYidongNews(list, "");
            list = GetYidongNews(list, "", "54");
            list = GetYidongNews(list, "", "56");
            list = GetNewListWhere(list, "");
            if (list != null)
            {
                elist = list.OrderByDescending(p => p.PublDate).Take(200);
                Cache.Add("GetAllNewsInfo", elist, DateTime.Now.AddMinutes(5));
            }
        }
        else
            elist = o as IEnumerable;
        return elist;
    }

    /// <summary>
    /// 要闻
    /// </summary>
    /// <param name="list"></param>
    /// <param name="level"></param>
    /// <returns></returns>
    private List<NewsTextModel> GetNewListWhere(List<NewsTextModel> list, string level)
    {
        NewsBLL bll = new NewsBLL();

        DataTable dtEM = new DataTable();
        if (string.IsNullOrEmpty(level))
            dtEM = dal.GetEMWebNews("0101");
        else
            dtEM = dal.GetEMWebNews("0101", level);
        int rowsCount = dtEM.Rows.Count;
        for (int n = 0; n < rowsCount; n++)
        {
            if (n == 200)
                break;
            NewsTextModel model = new NewsTextModel();
            model.TextID = dtEM.Rows[n]["n_id"].ToString();
            string result = bll.GetByIdStr(Convert.ToInt64(model.TextID));
            var resu = Newtonsoft.Json.JsonConvert.DeserializeObject<NewsEntity>(result);
            if (resu != null)
            {
                model.PublDate = resu.SPTime;
                DataRow[] drs = dtEM.Select("n_id='" + model.TextID + "'");
                if (drs != null && drs.Length > 0)
                    model.Title = drs[0]["n_title"].ToString();
                if (string.IsNullOrEmpty(model.Title))
                {
                    model.Title = resu.Title;
                }
                model.TextContent = resu.Content;
                list.Add(model);
            }
        }
        return list;
    }

    /// <summary>
    /// 个股异动
    /// </summary>
    /// <param name="list"></param>
    /// <param name="level"></param>
    /// <returns></returns>
    private List<NewsTextModel> GetGeGuYidongNews(List<NewsTextModel> list, string level)
    {
        DataTable dt = new DataTable();
        DataTable dtEM = new DataTable();
        if (string.IsNullOrEmpty(level))
            dtEM = dal.GetEMWebNews("0");
        else
            dtEM = dal.GetEMWebNews("0", level);
        StringBuilder strWhere = new StringBuilder();
        for (int i = 0; i < dtEM.Rows.Count; i++)
        {
            strWhere.Append(",'" + dtEM.Rows[i]["n_id"] + "'");
        }
        if (strWhere != null && strWhere.ToString() != "")
        {
            strWhere = strWhere.Remove(0, 1);
            dt = dal.GetStockAbnormalMsgWhere(strWhere.ToString());
        }
        int rowsCount = dt.Rows.Count;
        if (rowsCount > 0)
        {
            for (int n = 0; n < rowsCount; n++)
            {
                NewsTextModel model = new NewsTextModel();
                if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "")
                {
                    model.TextID = dt.Rows[n]["id"].ToString();
                }
                if (dt.Rows[n]["modify_time"] != null && dt.Rows[n]["modify_time"].ToString() != "")
                {
                    model.PublDate = dt.Rows[n]["modify_time"].ToString();
                }
                DataRow[] drs = dtEM.Select("n_id='" + model.TextID+"'");
                if (drs != null && drs.Length > 0)
                    model.Title = drs[0]["n_title"].ToString();
                if (string.IsNullOrEmpty(model.Title))
                {
                    model.Title = dt.Rows[n]["case_summary"].ToString();
                }
                if (dt.Rows[n]["case_content"] != null && dt.Rows[n]["case_content"].ToString() != "")
                {
                    model.TextContent = dt.Rows[n]["case_content"].ToString();
                }

                list.Add(model);
            }
        }
        return list;
    }

    /// <summary>
    /// 返回所有后台维护的异动
    /// </summary>
    /// <param name="list"></param>
    /// <param name="level"></param>
    /// <param name="typeid">56、54</param>
    /// <returns></returns>
    private List<NewsTextModel> GetYidongNews(List<NewsTextModel> list, string level, string typeid)
    {
        DataTable dt = new DataTable();
        DataTable dtEM = new DataTable();
        if (string.IsNullOrEmpty(level))
            dtEM = dal.GetEMWebNews(typeid);
        else
            dtEM = dal.GetEMWebNews(typeid, level);
        StringBuilder strWhere = new StringBuilder();
        for (int i = 0; i < dtEM.Rows.Count; i++)
        {
            if (i == 100)
                break;
            strWhere.Append(",'" + dtEM.Rows[i]["n_id"] + "'");
        }
        if (strWhere != null && strWhere.ToString() != "")
        {
            strWhere = strWhere.Remove(0, 1);
            DataSet ds = dal.GetDataModelPagination("*", "n_modifyDate", 200, 1, 0, 1, "n_id in (" + strWhere + ")", 200, true);
            if (ds != null && ds.Tables.Count > 0)
                dt = ds.Tables[0];
        }
        int rowsCount = dt.Rows.Count;
        if (rowsCount > 0)
        {
            for (int n = 0; n < rowsCount; n++)
            {
                NewsTextModel model = new NewsTextModel();
                if (dt.Rows[n]["n_id"] != null && dt.Rows[n]["n_id"].ToString() != "")
                {
                    model.TextID = dt.Rows[n]["n_id"].ToString();
                }
                if (dt.Rows[n]["n_modifyDate"] != null && dt.Rows[n]["n_modifyDate"].ToString() != "")
                {
                    model.PublDate = dt.Rows[n]["n_modifyDate"].ToString();
                }
                DataRow[] drs = dtEM.Select("n_id='" + model.TextID + "'");
                if (drs != null && drs.Length > 0)
                    model.Title = drs[0]["n_title"].ToString();
                if (string.IsNullOrEmpty(model.Title))
                {
                    model.Title = dt.Rows[n]["n_title"].ToString();
                }
                if (dt.Rows[n]["n_content"] != null && dt.Rows[n]["n_content"].ToString() != "")
                {
                    model.TextContent = dt.Rows[n]["n_content"].ToString();
                }

                list.Add(model);
            }
        }
        return list;
    }

    #region 旧接口

    /// <summary>
    /// 获取所有后台维护今日要闻，包括财经新闻(内地财经)、异动板块、新闻和异动888888中的最新一条数据
    /// </summary>
    /// <returns></returns>
    public IEnumerable GetAllNews()
    {
        IEnumerable elist = null;
        List<NewsTextModel> list = new List<NewsTextModel>();
        object o = Cache.Get("GetAllNews");
        if (o == null)
        {
            list = GetNeidiNews(list, "");
            list = GetXinwenNews(list, "");
            list = GetYidongNews(list, "");
            list = GetStockAbnormalNews(list);
            if (list != null)
            {
                elist = list.OrderByDescending(p => p.PublDate).Take(200);
                Cache.Add("GetAllNews", elist, DateTime.Now.AddMinutes(5));
            }
        }
        else
            elist = o as IEnumerable;
        return elist;
    }

    /// <summary>
    /// 异动888888中的最新一条数据
    /// </summary>
    /// <param name="list"></param>
    /// <returns></returns>
    private List<NewsTextModel> GetStockAbnormalNews(List<NewsTextModel> list)
    {
        DataTable dt = GetStockAbnormalMsg("888888");
        int rowsCount = dt.Rows.Count;
        if (rowsCount > 0)
        {
            NewsTextModel model = new NewsTextModel();
            if (dt.Rows[0]["id"] != null && dt.Rows[0]["id"].ToString() != "")
            {
                model.TextID = dt.Rows[0]["id"].ToString();
            }
            if (dt.Rows[0]["modify_time"] != null && dt.Rows[0]["modify_time"].ToString() != "")
            {
                model.PublDate = dt.Rows[0]["modify_time"].ToString();
            }
            if (dt.Rows[0]["case_summary"] != null && dt.Rows[0]["case_summary"].ToString() != "")
            {
                model.Title = dt.Rows[0]["case_summary"].ToString();
            }
            if (dt.Rows[0]["case_content"] != null && dt.Rows[0]["case_content"].ToString() != "")
            {
                model.TextContent = dt.Rows[0]["case_content"].ToString();
            }

            list.Add(model);
        }
        return list;
    }

    /// <summary>
    /// 返回所有后台维护的异动板块56
    /// </summary>
    /// <param name="list"></param>
    /// <returns></returns>
    private List<NewsTextModel> GetYidongNews(List<NewsTextModel> list, string level)
    {
        DataTable dt = new DataTable();
        DataTable dtEM = new DataTable();
        if (string.IsNullOrEmpty(level))
            dtEM = dal.GetEMWebNews("56");
        else
            dtEM = dal.GetEMWebNews("56", level);
        StringBuilder strWhere = new StringBuilder();
        for (int i = 0; i < dtEM.Rows.Count; i++)
        {
            if (i == 100)
                break;
            strWhere.Append(",'" + dtEM.Rows[i]["n_id"] + "'");
        }
        if (strWhere != null && strWhere.ToString() != "")
        {
            strWhere = strWhere.Remove(0, 1);
            DataSet ds = dal.GetDataModelPagination("*", "n_modifyDate", 200, 1, 0, 1, "n_id in (" + strWhere + ")", 200, true);
            if (ds.Tables.Count > 0)
                dt = ds.Tables[0];
        }
        int rowsCount = dt.Rows.Count;
        if (rowsCount > 0)
        {
            for (int n = 0; n < rowsCount; n++)
            {
                NewsTextModel model = new NewsTextModel();
                if (dt.Rows[n]["n_id"] != null && dt.Rows[n]["n_id"].ToString() != "")
                {
                    model.TextID = dt.Rows[n]["n_id"].ToString();
                }
                if (dt.Rows[n]["n_modifyDate"] != null && dt.Rows[n]["n_modifyDate"].ToString() != "")
                {
                    model.PublDate = dt.Rows[n]["n_modifyDate"].ToString();
                }
                if (dt.Rows[n]["n_title"] != null && dt.Rows[n]["n_title"].ToString() != "")
                {
                    model.Title = dt.Rows[n]["n_title"].ToString();
                }
                if (dt.Rows[n]["n_content"] != null && dt.Rows[n]["n_content"].ToString() != "")
                {
                    model.TextContent = dt.Rows[n]["n_content"].ToString();
                }

                list.Add(model);
            }
        }
        return list;
    }

    /// <summary>
    /// 返回所有后台维护的新闻020107
    /// </summary>
    /// <param name="list"></param>
    /// <returns></returns>
    private List<NewsTextModel> GetXinwenNews(List<NewsTextModel> list, string level)
    {
        DataTable dt = new DataTable();
        DataTable dtEM = new DataTable();
        if (string.IsNullOrEmpty(level))
            dtEM = dal.GetEMWebNews("020107");
        else
            dtEM = dal.GetEMWebNews("020107", level);
        StringBuilder strWhere = new StringBuilder();
        for (int i = 0; i < dtEM.Rows.Count; i++)
        {
            strWhere.Append(",'" + dtEM.Rows[i]["n_id"] + "'");
        }
        if (strWhere != null && strWhere.ToString() != "")
        {
            strWhere = strWhere.Remove(0, 1);
            dt = dal.GetNEWSTEXTByWhere(strWhere.ToString());
        }
        int rowsCount = dt.Rows.Count;
        if (rowsCount > 0)
        {
            for (int n = 0; n < rowsCount; n++)
            {
                NewsTextModel model = new NewsTextModel();
                if (dt.Rows[n]["TextID"] != null && dt.Rows[n]["TextID"].ToString() != "")
                {
                    model.TextID = dt.Rows[n]["TextID"].ToString();
                }
                if (dt.Rows[n]["PublDate"] != null && dt.Rows[n]["PublDate"].ToString() != "")
                {
                    model.PublDate = dt.Rows[n]["PublDate"].ToString();
                }
                if (dt.Rows[n]["Title"] != null && dt.Rows[n]["Title"].ToString() != "")
                {
                    model.Title = dt.Rows[n]["Title"].ToString();
                }
                if (dt.Rows[n]["TextContent"] != null && dt.Rows[n]["TextContent"].ToString() != "")
                {
                    model.TextContent = dt.Rows[n]["TextContent"].ToString();
                }

                list.Add(model);
            }
        }
        return list;
    }

    /// <summary>
    /// 返回所有后台维护的财经新闻(内地财经)020103
    /// </summary>
    /// <param name="list"></param>
    /// <returns></returns>
    private List<NewsTextModel> GetNeidiNews(List<NewsTextModel> list, string level)
    {
        DataTable dt = new DataTable();
        DataTable dtEM = new DataTable();
        if (string.IsNullOrEmpty(level))
            dtEM = dal.GetEMWebNews("020103");
        else
            dtEM = dal.GetEMWebNews("020103", level);
        StringBuilder strWhere = new StringBuilder();
        for (int i = 0; i < dtEM.Rows.Count; i++)
        {
            strWhere.Append(",'" + dtEM.Rows[i]["n_id"] + "'");
        }
        if (strWhere != null && strWhere.ToString() != "")
        {
            strWhere = strWhere.Remove(0, 1);
            dt = dal.GetNEWSTEXTByWhere(strWhere.ToString());
        }
        int rowsCount = dt.Rows.Count;
        if (rowsCount > 0)
        {
            for (int n = 0; n < rowsCount; n++)
            {
                NewsTextModel model = new NewsTextModel();
                if (dt.Rows[n]["TextID"] != null && dt.Rows[n]["TextID"].ToString() != "")
                {
                    model.TextID = dt.Rows[n]["TextID"].ToString();
                }
                if (dt.Rows[n]["PublDate"] != null && dt.Rows[n]["PublDate"].ToString() != "")
                {
                    model.PublDate = dt.Rows[n]["PublDate"].ToString();
                }
                if (dt.Rows[n]["Title"] != null && dt.Rows[n]["Title"].ToString() != "")
                {
                    model.Title = dt.Rows[n]["Title"].ToString();
                }
                if (dt.Rows[n]["TextContent"] != null && dt.Rows[n]["TextContent"].ToString() != "")
                {
                    model.TextContent = dt.Rows[n]["TextContent"].ToString();
                }

                list.Add(model);
            }
        }
        return list;
    }
    #endregion

    #endregion

    /// <summary>
    /// 获取数据列表
    /// </summary>
    /// <param name="id">数据类型</param>
    /// <returns></returns>
    public List<NewsTextModel> GetNewsTextList(string id)
    {
        List<NewsTextModel> modelList = new List<NewsTextModel>();
        try
        {
            DataTable dt = GetNEWSTEXT(id);
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                NewsTextModel model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new NewsTextModel();
                    if (dt.Rows[n]["TextID"] != null && dt.Rows[n]["TextID"].ToString() != "")
                    {
                        model.TextID = dt.Rows[n]["TextID"].ToString();
                    }
                    if (dt.Rows[n]["Author"] != null && dt.Rows[n]["Author"].ToString() != "")
                    {
                        model.Author = dt.Rows[n]["Author"].ToString();
                    }
                    if (dt.Rows[n]["PublishOrg"] != null && dt.Rows[n]["PublishOrg"].ToString() != "")
                    {
                        model.PublishOrg = dt.Rows[n]["PublishOrg"].ToString();
                    }
                    if (dt.Rows[n]["InitialMedia"] != null && dt.Rows[n]["InitialMedia"].ToString() != "")
                    {
                        model.InitialMedia = dt.Rows[n]["InitialMedia"].ToString();
                    }
                    if (dt.Rows[n]["PublDate"] != null && dt.Rows[n]["PublDate"].ToString() != "")
                    {
                        model.PublDate = dt.Rows[n]["PublDate"].ToString();
                    }
                    if (dt.Rows[n]["Title"] != null && dt.Rows[n]["Title"].ToString() != "")
                    {
                        model.Title = dt.Rows[n]["Title"].ToString();
                    }
                    if (dt.Rows[n]["KeyWords"] != null && dt.Rows[n]["KeyWords"].ToString() != "")
                    {
                        model.KeyWords = dt.Rows[n]["KeyWords"].ToString();
                    }
                    if (dt.Rows[n]["TextContent"] != null && dt.Rows[n]["TextContent"].ToString() != "")
                    {
                        model.TextContent = dt.Rows[n]["TextContent"].ToString();
                    }
                    if (dt.Rows[n]["TextAbstract"] != null && dt.Rows[n]["TextAbstract"].ToString() != "")
                    {
                        model.TextAbstract = dt.Rows[n]["TextAbstract"].ToString();
                    }
                    if (dt.Rows[n]["TextSize"] != null && dt.Rows[n]["TextSize"].ToString() != "")
                    {
                        model.TextSize = decimal.Parse(dt.Rows[n]["TextSize"].ToString());
                    }
                    if (dt.Rows[n]["TextComment"] != null && dt.Rows[n]["TextComment"].ToString() != "")
                    {
                        model.TextComment = dt.Rows[n]["TextComment"].ToString();
                    }
                    if (dt.Rows[n]["IndustryCode"] != null && dt.Rows[n]["IndustryCode"].ToString() != "")
                    {
                        model.IndustryCode = dt.Rows[n]["IndustryCode"].ToString();
                    }
                    if (dt.Rows[n]["IndustryName"] != null && dt.Rows[n]["IndustryName"].ToString() != "")
                    {
                        model.IndustryName = dt.Rows[n]["IndustryName"].ToString();
                    }
                    if (dt.Rows[n]["Person"] != null && dt.Rows[n]["Person"].ToString() != "")
                    {
                        model.Person = dt.Rows[n]["Person"].ToString();
                    }
                    if (dt.Rows[n]["RecommendID"] != null && dt.Rows[n]["RecommendID"].ToString() != "")
                    {
                        model.RecommendID = dt.Rows[n]["RecommendID"].ToString();
                    }
                    if (dt.Rows[n]["Memo"] != null && dt.Rows[n]["Memo"].ToString() != "")
                    {
                        model.Memo = dt.Rows[n]["Memo"].ToString();
                    }
                    if (dt.Rows[n]["RecTime"] != null && dt.Rows[n]["RecTime"].ToString() != "")
                    {
                        model.RecTime = dt.Rows[n]["RecTime"].ToString();
                    }
                    if (dt.Rows[n]["ModTime"] != null && dt.Rows[n]["ModTime"].ToString() != "")
                    {
                        model.ModTime = dt.Rows[n]["ModTime"].ToString();
                    }
                    if (dt.Rows[n]["IsValid"] != null && dt.Rows[n]["IsValid"].ToString() != "")
                    {
                        model.IsValid = dt.Rows[n]["IsValid"].ToString();
                    }
                    if (dt.Rows[n]["RecordID"] != null && dt.Rows[n]["RecordID"].ToString() != "")
                    {
                        model.RecordID = dt.Rows[n]["RecordID"].ToString();
                    }
                    modelList.Add(model);
                }
            }
        }
        catch { }
        return modelList;
    }

    /// <summary>
    /// 获取公司公告数据
    /// </summary>
    /// <param name="key"></param>
    /// <returns></returns>
    public List<AnnounceTxtInfoModel> GetAnnounceTxtInfoList(int key)
    {
        List<AnnounceTxtInfoModel> modelList = new List<AnnounceTxtInfoModel>();
        try
        {
            DataTable dt = GetAnnounceTxtInfo(key);
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                AnnounceTxtInfoModel model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new AnnounceTxtInfoModel();
                    if (dt.Rows[n]["TextID"] != null && dt.Rows[n]["TextID"].ToString() != "")
                    {
                        model.TextID = dt.Rows[n]["TextID"].ToString();
                    }
                    if (dt.Rows[n]["TextCode"] != null && dt.Rows[n]["TextCode"].ToString() != "")
                    {
                        model.TextCode = dt.Rows[n]["TextCode"].ToString();
                    }
                    if (dt.Rows[n]["PublDate"] != null && dt.Rows[n]["PublDate"].ToString() != "")
                    {
                        model.PublDate = dt.Rows[n]["PublDate"].ToString();
                    }
                    if (dt.Rows[n]["AnnounceDate"] != null && dt.Rows[n]["AnnounceDate"].ToString() != "")
                    {
                        model.AnnounceDate = dt.Rows[n]["AnnounceDate"].ToString();
                    }
                    if (dt.Rows[n]["AnnounceTitle"] != null && dt.Rows[n]["AnnounceTitle"].ToString() != "")
                    {
                        model.AnnounceTitle = dt.Rows[n]["AnnounceTitle"].ToString();
                    }
                    if (dt.Rows[n]["AnnounceContent"] != null && dt.Rows[n]["AnnounceContent"].ToString() != "")
                    {
                        model.AnnounceContent = dt.Rows[n]["AnnounceContent"].ToString();
                    }
                    if (dt.Rows[n]["AnnounceSize"] != null && dt.Rows[n]["AnnounceSize"].ToString() != "")
                    {
                        model.AnnounceSize = decimal.Parse(dt.Rows[n]["AnnounceSize"].ToString());
                    }
                    if (dt.Rows[n]["Memo"] != null && dt.Rows[n]["Memo"].ToString() != "")
                    {
                        model.Memo = dt.Rows[n]["Memo"].ToString();
                    }
                    if (dt.Rows[n]["RecTime"] != null && dt.Rows[n]["RecTime"].ToString() != "")
                    {
                        model.RecTime = dt.Rows[n]["RecTime"].ToString();
                    }
                    if (dt.Rows[n]["ModTime"] != null && dt.Rows[n]["ModTime"].ToString() != "")
                    {
                        model.ModTime = dt.Rows[n]["ModTime"].ToString();
                    }
                    if (dt.Rows[n]["IsValid"] != null && dt.Rows[n]["IsValid"].ToString() != "")
                    {
                        model.IsValid = dt.Rows[n]["IsValid"].ToString();
                    }
                    if (dt.Rows[n]["RecordID"] != null && dt.Rows[n]["RecordID"].ToString() != "")
                    {
                        model.RecordID = dt.Rows[n]["RecordID"].ToString();
                    }
                    if (dt.Rows[n]["SEQID"] != null && dt.Rows[n]["SEQID"].ToString() != "")
                    {
                        model.SEQID = dt.Rows[n]["SEQID"].ToString();
                    }
                    modelList.Add(model);
                }
            }
        }
        catch
        { }
        return modelList;
    }

    /// <summary>
    /// 获取基础行情数据
    /// </summary>
    /// <param name="id">数据类型(id=888888大盘异动)</param>
    /// <returns></returns>
    public List<StockAbnormalMsgModel> GetStockAbnormalMsgList(string id)
    {
        List<StockAbnormalMsgModel> modelList = new List<StockAbnormalMsgModel>();
        try
        {
            DataTable dt = GetStockAbnormalMsg(id);
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                StockAbnormalMsgModel model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new StockAbnormalMsgModel();
                    if (dt.Rows[n]["stock_id"] != null && dt.Rows[n]["stock_id"].ToString() != "")
                    {
                        model.stock_id = dt.Rows[n]["stock_id"].ToString();
                    }
                    if (dt.Rows[n]["stock_name"] != null && dt.Rows[n]["stock_name"].ToString() != "")
                    {
                        model.stock_name = dt.Rows[n]["stock_name"].ToString();
                    }
                    if (dt.Rows[n]["abnormal_date"] != null && dt.Rows[n]["abnormal_date"].ToString() != "")
                    {
                        model.abnormal_date = dt.Rows[n]["abnormal_date"].ToString();
                    }
                    if (dt.Rows[n]["master"] != null && dt.Rows[n]["master"].ToString() != "")
                    {
                        model.master = dt.Rows[n]["master"].ToString();
                    }
                    if (dt.Rows[n]["increase"] != null && dt.Rows[n]["increase"].ToString() != "")
                    {
                        model.increase = dt.Rows[n]["increase"].ToString();
                    }
                    if (dt.Rows[n]["last_month_rate"] != null && dt.Rows[n]["last_month_rate"].ToString() != "")
                    {
                        model.last_month_rate = dt.Rows[n]["last_month_rate"].ToString();
                    }
                    if (dt.Rows[n]["reason"] != null && dt.Rows[n]["reason"].ToString() != "")
                    {
                        model.reason = dt.Rows[n]["reason"].ToString();
                    }
                    if (dt.Rows[n]["case_date"] != null && dt.Rows[n]["case_date"].ToString() != "")
                    {
                        model.case_date = dt.Rows[n]["case_date"].ToString();
                    }
                    if (dt.Rows[n]["case_summary"] != null && dt.Rows[n]["case_summary"].ToString() != "")
                    {
                        model.case_summary = dt.Rows[n]["case_summary"].ToString();
                    }
                    if (dt.Rows[n]["case_content"] != null && dt.Rows[n]["case_content"].ToString() != "")
                    {
                        model.case_content = dt.Rows[n]["case_content"].ToString();
                    }
                    if (dt.Rows[n]["cancel_date"] != null && dt.Rows[n]["cancel_date"].ToString() != "")
                    {
                        model.cancel_date = dt.Rows[n]["cancel_date"].ToString();
                    }
                    if (dt.Rows[n]["major_short_reason"] != null && dt.Rows[n]["major_short_reason"].ToString() != "")
                    {
                        model.major_short_reason = dt.Rows[n]["major_short_reason"].ToString();
                    }
                    if (dt.Rows[n]["major_long_reason"] != null && dt.Rows[n]["major_long_reason"].ToString() != "")
                    {
                        model.major_long_reason = dt.Rows[n]["major_long_reason"].ToString();
                    }
                    if (dt.Rows[n]["msg_oper"] != null && dt.Rows[n]["msg_oper"].ToString() != "")
                    {
                        model.msg_oper = dt.Rows[n]["msg_oper"].ToString();
                    }
                    if (dt.Rows[n]["msg_confirm"] != null && dt.Rows[n]["msg_confirm"].ToString() != "")
                    {
                        model.msg_confirm = dt.Rows[n]["msg_confirm"].ToString();
                    }
                    if (dt.Rows[n]["major_oper"] != null && dt.Rows[n]["major_oper"].ToString() != "")
                    {
                        model.major_oper = dt.Rows[n]["major_oper"].ToString();
                    }
                    if (dt.Rows[n]["major_confirm"] != null && dt.Rows[n]["major_confirm"].ToString() != "")
                    {
                        model.major_confirm = dt.Rows[n]["major_confirm"].ToString();
                    }
                    if (dt.Rows[n]["affect"] != null && dt.Rows[n]["affect"].ToString() != "")
                    {
                        model.affect = dt.Rows[n]["affect"].ToString();
                    }
                    if (dt.Rows[n]["memo"] != null && dt.Rows[n]["memo"].ToString() != "")
                    {
                        model.memo = dt.Rows[n]["memo"].ToString();
                    }
                    if (dt.Rows[n]["modify_time"] != null && dt.Rows[n]["modify_time"].ToString() != "")
                    {
                        model.modify_time = dt.Rows[n]["modify_time"].ToString();
                    }
                    if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    modelList.Add(model);
                }
            }
        }
        catch
        {
        }
        return modelList;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public List<EPioneerDataModel> GetNewsName(int id)
    {
        return dal.GetNewsName(id, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3);
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public List<EPioneerDataModel> GetDataModelPagination()
    {
        List<EPioneerDataModel> list = new List<EPioneerDataModel>();
        try
        {
            DataSet ds = new DataSet();
            object cacheData = Cache.Get("GetDataModelPagination56");
            if (cacheData == null)
            {
                DataTable dtEM = dal.GetEMWebNews("56");
                StringBuilder strWhere = new StringBuilder();
                for (int i = 0; i < dtEM.Rows.Count; i++)
                {
                    if (i == 100)
                        break;
                    strWhere.Append(",'" + dtEM.Rows[i]["n_id"] + "'");
                }
                if (strWhere != null && strWhere.ToString() != "")
                {
                    strWhere = strWhere.Remove(0, 1);
                    ds = dal.GetDataModelPagination("*", "n_modifyDate", 200, 1, 0, 1, "n_id in (" + strWhere + ")", 200, true);
                }
                if (ds == null || ds.Tables.Count < 1 || ds.Tables[0].Rows.Count < 1)
                {
                    ds = dal.GetDataModelPagination("*", "n_modifyDate", 200, 1, 0, 1, "n_subclassid=56", 200, true);
                }
                Cache.Add("GetDataModelPagination56", ds, DateTime.Now.AddMinutes(5));
            }
            else
                ds = Cache.Get("GetDataModelPagination56") as DataSet;
            list = GetListModel(ds);
        }
        catch
        {
        }
        return list;
    }

    private List<EPioneerDataModel> GetListModel(DataSet ds)
    {
        List<EPioneerDataModel> list = new List<EPioneerDataModel>();
        if (ds.Tables.Count > 0)
        {
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                EPioneerDataModel model = new EPioneerDataModel();
                model.corSymbol = ds.Tables[0].Rows[i]["corSymbol"].ToString();
                model.hidden = ds.Tables[0].Rows[i]["hidden"].ToString();
                //model.m_lm = ds.Tables[0].Rows[i]["m_lm"].ToString();
                model.n_Abstract = ds.Tables[0].Rows[i]["n_Abstract"].ToString();
                model.n_author = ds.Tables[0].Rows[i]["n_author"].ToString();
                model.n_bigclassid = String.IsNullOrEmpty(ds.Tables[0].Rows[i]["n_bigclassid"].ToString()) ? -1 : Convert.ToInt32(ds.Tables[0].Rows[i]["n_bigclassid"].ToString());
                model.n_content = ds.Tables[0].Rows[i]["n_content"].ToString();
                model.n_createdate = String.IsNullOrEmpty(ds.Tables[0].Rows[i]["n_createdate"].ToString()) ? DateTime.MinValue : Convert.ToDateTime(ds.Tables[0].Rows[i]["n_createdate"].ToString());
                model.n_enddate = String.IsNullOrEmpty(ds.Tables[0].Rows[i]["n_enddate"].ToString()) ? DateTime.MinValue : Convert.ToDateTime(ds.Tables[0].Rows[i]["n_enddate"].ToString());
                model.n_id = String.IsNullOrEmpty(ds.Tables[0].Rows[i]["n_id"].ToString()) ? -1 : Convert.ToInt32(ds.Tables[0].Rows[i]["n_id"].ToString());
                model.n_Isgo = String.IsNullOrEmpty(ds.Tables[0].Rows[i]["n_Isgo"].ToString()) ? -1 : Convert.ToInt32(ds.Tables[0].Rows[i]["n_Isgo"].ToString());
                model.n_ISpublic = ds.Tables[0].Rows[i]["n_ISpublic"].ToString();
                model.n_Level = String.IsNullOrEmpty(ds.Tables[0].Rows[i]["n_Level"].ToString()) ? -1 : Convert.ToInt32(ds.Tables[0].Rows[i]["n_Level"].ToString());
                model.n_mark = ds.Tables[0].Rows[i]["n_mark"].ToString();
                model.n_modifyDate = String.IsNullOrEmpty(ds.Tables[0].Rows[i]["n_modifyDate"].ToString()) ? DateTime.MinValue : Convert.ToDateTime(ds.Tables[0].Rows[i]["n_modifyDate"].ToString());
                //model.n_orderby = String.IsNullOrEmpty(ds.Tables[0].Rows[i]["n_orderby"].ToString()) ? -1 : Convert.ToInt32(ds.Tables[0].Rows[i]["n_orderby"].ToString());
                model.n_origin = ds.Tables[0].Rows[i]["n_origin"].ToString();
                model.n_subclassid = String.IsNullOrEmpty(ds.Tables[0].Rows[i]["n_subclassid"].ToString()) ? -1 : Convert.ToInt32(ds.Tables[0].Rows[i]["n_subclassid"].ToString());
                model.n_title = ds.Tables[0].Rows[i]["n_title"].ToString();
                model.n_url = ds.Tables[0].Rows[i]["n_url"].ToString();
                model.optionContent = ds.Tables[0].Rows[i]["optionContent"].ToString();
                model.optionType = String.IsNullOrEmpty(ds.Tables[0].Rows[i]["optionType"].ToString()) ? -1 : Convert.ToInt32(ds.Tables[0].Rows[i]["optionType"].ToString());
                model.userType = String.IsNullOrEmpty(ds.Tables[0].Rows[i]["userType"].ToString()) ? -1 : Convert.ToInt32(ds.Tables[0].Rows[i]["userType"].ToString());
                list.Add(model);
            }
        }
        return list;
    }

    /// <summary>
    /// 从缓存中获取数据
    /// </summary>
    /// <param name="id">数据类型</param>
    /// <returns></returns>
    private DataTable GetNEWSTEXT(string id)
    {
        object o = Cache.Get("GetNewsTextBySortCode" + id);
        DataTable dt = new DataTable();
        if (o == null)
        {
            if (id == "020103")
            {
                DataTable dtEM = dal.GetEMWebNews("020103");
                StringBuilder strWhere = new StringBuilder();
                for (int i = 0; i < dtEM.Rows.Count; i++)
                {
                    strWhere.Append(",'" + dtEM.Rows[i]["n_id"] + "'");
                }
                if (strWhere != null && strWhere.ToString() != "")
                {
                    strWhere = strWhere.Remove(0, 1);
                    dt = dal.GetNEWSTEXTByWhere(strWhere.ToString());
                }
                if (dt == null || dt.Rows.Count < 1)
                    dt = dal.GetNEWSTEXT(id);
            }
            else
                dt = dal.GetNEWSTEXT(id);
            Cache.Add("GetNewsTextBySortCode" + id, dt, DateTime.Now.AddMinutes(5));
        }
        else
            dt = o as DataTable;
        return dt;
    }

    /// <summary>
    /// 从缓存中获取基础行情数据
    /// </summary>
    /// <param name="id">数据类型(id=888888大盘异动)</param>
    /// <returns></returns>
    private DataTable GetStockAbnormalMsg(string id)
    {
        object o = Cache.Get("GetStockAbnormalMsg" + id);
        DataTable dt = new DataTable();
        if (o == null)
        {
            dt = dal.GetStockAbnormalMsg(id);
            Cache.Add("GetStockAbnormalMsg" + id, dt, DateTime.Now.AddMinutes(5));
        }
        else
            dt = o as DataTable;
        return dt;
    }

    /// <summary>
    /// 从缓存中获取公司公告数据
    /// </summary>
    /// <returns></returns>
    private DataTable GetAnnounceTxtInfo(int key)
    {
        object o = Cache.Get("GetAnnounceTxtInfo" + key);
        DataTable dt = new DataTable();
        if (o == null)
        {
            dt = dal.GetAnnounceTxtInfo();
            Cache.Add("GetAnnounceTxtInfo" + key, dt, DateTime.Now.AddMinutes(5));
        }
        else
            dt = o as DataTable;
        return dt;
    }
}